<html>
	<head>
		<title>Marbles 3D</title>
		<script type="text/javascript" src="/third-party-libs/jquery-3.1.1.min.js"></script>
		<script type="text/javascript" src="/third-party-libs/three.min.js"></script>
		<script type="text/javascript" src="/libs/FirstPersonControls.js"></script>
		<script type="text/javascript" src="/libs/MarblesViewEngine.js"></script>
		<script type="text/javascript" src="/libs/MarblesGeometry.js"></script>
		<script type="text/javascript" src="/libs/levelViewer.js"></script>
		<script type="text/javascript" src="/libs/general.js"></script>
	  	<link type="text/css" href="/css/site.css" rel="stylesheet" />
	  	<link type="text/css" href="/css/main.css" rel="stylesheet" />
	</head>
	<body>
		<div id="scene-container"></div>
		<div id="loading-overlay">
    		<span></span>
			<img src="/images/loading.gif" border="0" />
		</div>
		<div id="modal-dialog-overlay" style="display: none;"></div>
		<script type="text/javascript">	
			function closeModalDialog() {
				$("#modal-dialog-overlay").empty();
				$("#modal-dialog-overlay").hide();
			}

			function setTitle() {
				document.title = levelViewer.getName();
			}

			// Binding window events

			document.addEventListener("mouseout", function() {
				levelViewer.cancelMovement();
			}, false);

			document.addEventListener('keydown', function(e) {
				e.stopPropagation();
				e.preventDefault();
			});

			document.addEventListener('keyup', function(e) {
				e.stopPropagation();
				e.preventDefault();
			}, false);

			var levelViewer = new LevelViewer();

			levelViewer.start("scene-container");
			
			levelViewer.onError = function(message) {
                $.ajax({
                    url: "/dialogs/error",
                    type: "GET",
                    success: function (response) {
						$("#modal-dialog-overlay").html(response);

						$("#error-message").html(message);

						$("#modal-dialog-overlay").show();
                    }
                });
			};

			levelViewer.onLoad = function(loaded) { 
				if (loaded) setTitle();

				$("#loading-overlay").hide();
			};

			var sceneId = getURLParam("id");
			if (sceneId != null) levelViewer.load(sceneId);
		</script>
	</body>
</html>